package com.atguigu.gmall.web.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.vo.IndexCategoryVo;
import com.atguigu.gmall.web.all.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;


/**
 * @author dyqstart
 * @create 2021-08-11-21:30
 * @since 1.0.0
 */
@Controller
public class IndexController {


    @Autowired
    IndexService indexService;

    @GetMapping({"/","/index.html"})
    public String index(Model model){

        //调用商品远程服务查询
        List<IndexCategoryVo> list = indexService.getIndexCategory();
        int i =1;
        for (IndexCategoryVo indexCategoryVo : list) {
            indexCategoryVo.setIndex(i++);
        }

        model.addAttribute("list",list);

        return "index/index";
    }
}
